//
//  UserManage.m
//  AI
//
//  Created by zjhc on 2018/1/11.
//  Copyright © 2018年 zjhc. All rights reserved.
//

#import "UserManage.h"
#import "User.h"

@implementation UserManage 

singleton_implementation(UserManage)


/**
 *  用户名字
 */
- (void)setUserName:(NSString *)userName{
    
    NSString *lasetuserName = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
    if (userName == nil) {
        //意味着清除该数据
        if (lasetuserName) {
            
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"userName"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }
    }else{
        
        [[NSUserDefaults standardUserDefaults]setObject:userName forKey:@"userName"];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
}

- (NSString *)userName{
    
    NSString *str = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
    if (str) {
        return str;
    }
    
    return nil;
}

/**
 *  用户密码
 */
- (void)setUserPassword:(NSString *)userPassword{
    NSString *lasetuserPassword = [[NSUserDefaults standardUserDefaults]objectForKey:@"password"];
    if (userPassword == nil) {
        //意味着清除该数据
        if (lasetuserPassword) {
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"password"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }
        
    }else{
        [[NSUserDefaults standardUserDefaults]setObject:userPassword forKey:@"password"];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
}
- (NSString *)userPassword{
    
    NSString *str = [[NSUserDefaults standardUserDefaults]objectForKey:@"password"];
    if (str) {
        return str;
    }
    return @"";
}


/**
 *  uid
 */
- (void)setUid:(NSString *)uid{
    NSString *lastUid = [[NSUserDefaults standardUserDefaults]objectForKey:@"uid"];
    if (uid == nil) {
        //意味着清除该数据
        if (lastUid) {
            [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"uid"];
            [[NSUserDefaults standardUserDefaults]synchronize];
        }
        
    }else{
        [[NSUserDefaults standardUserDefaults]setObject:uid forKey:@"uid"];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
}

- (NSString *)uid {
    
    NSString *str = [[NSUserDefaults standardUserDefaults]objectForKey:@"uid"];
    if (str) {
        return str;
    }
    return @"";
}

/**
 *  清除所有数据
 */
- (void)cleanAllUseData{
    
    self.userNmae = nil;
    self.password = nil;
    self.uid = nil;

}

@end
